﻿using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using ReAnimation.DAL.Domain;
using ReAnimation.DAL.RepositoryInterfaces;
using ReAnimation.MVP.ViewInterfaces;

namespace ReAnimation.MVP.Views
{
    public partial class ZMatrixTable : BaseUserControlView, IZMatrixTable
    {
        private ZMatrix _zMatrix;
        public ZMatrix ZMatrix
        {
            get
            {
                return GrabZMatrixFromTheTable();
            }
            set
            {
                LoadZMatrixIntoTable(value);
            }
        }

        public ZMatrixTable(IAtomDescriptionRepository atomDescriptionRepository)
        {
            InitializeComponent();
            Atom.Items.AddRange(atomDescriptionRepository.GetAll().ToArray());
        }

        private ZMatrix GrabZMatrixFromTheTable()
        {
            return new ZMatrix{ZMatrixLines = dataGridView.DataSource as IList<ZMatrixLine>};
        }

        private void LoadZMatrixIntoTable(ZMatrix zMatrix)
        {
            dataGridView.DataSource = zMatrix.ZMatrixLines;
        }
    }
}
